# 3.编写程序，实现分段函数的计算，分段函数的取值如下表所示。要求：可连续输入5次，每次的结果都将添加到列表中

"""
自变量x	因变量y
x＜0     0
0≤x＜5   x
5≤x＜10  3x-5
10≤x＜20 0.5x-2
x≥20	0
"""
count = 1
list1 = []

while count < 6:
    x = int(input('请输入x的值'))
    if x < 0:
        list1.append(0)
    elif 0 <= x < 5:
        list1.append(x)
    elif 5 <= x < 10:
        list1.append(3 * x - 5)
    elif 10 <= x < 20:
        list1.append(0.5 * x - 2)
    else:
        list1.append(0)
    count = count + 1

print(list1)


# 4.如果两个素数之差为2,这样的两个素数就叫作"孪生数",找出100以内的所有的素数保存到列表中，并找出其中的"孪生数"

ls = []
for num in range(2,101):
    flag = True
    for i in range(2,num):
        if num%i == 0:
            flag = False
            break
    if flag:
        ls.append(num)
print("1~100以内的素数有：")
print(ls)
i = 1
while i < len(ls):
    if ls[i] - ls[i - 1] == 2:
        print("{}和{}是孪生数".format(ls[i], ls[i - 1]),end="\n\n")
        if i == 6 or i == 10:
            print(" ")
    i += 1